<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择贴贴墙类型" clearable>
          <el-option
            v-for="dict in dict.type.app_likes_wall"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="审核状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择" clearable>
          <el-option
            v-for="dict in dict.type.app_check_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="likeWallList" @selection-change="handleSelectionChange">
      <el-table-column label="爱动ID" align="center" prop="platformId">
        <template slot-scope="scope">
          <a v-if="scope.row.sex === 1" style="color: #FF6EC7" @click="toUserInfo(scope.row.platformId)">{{ scope.row.platformId }}
          </a>
          <a v-else style="color: #7099F9" @click="toUserInfo(scope.row.platformId)">{{ scope.row.platformId }}
          </a>
        </template>
      </el-table-column>
      <el-table-column label="内容" align="center" prop="content"/>
      <el-table-column label="贴贴墙类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_likes_wall" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_check_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="发布时间" align="center" prop="createTime"/>
      <el-table-column label="审核人" align="center" prop="updateBy"/>
      <el-table-column label="审核时间" align="center" prop="updateTime"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button :disabled="scope.row.status!=1" size="mini" type="text" icon="el-icon-check"
                     @click="handlePass(scope.row)" v-hasPermi="['system:likeWall:pass']">审核通过
          </el-button>
          <el-button :disabled="scope.row.status!=1" size="mini" type="text" icon="el-icon-close"
                     @click="handleRefuse(scope.row)" v-hasPermi="['system:likeWall:refuse']">审核拒绝
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


    <!-- 通过审核 -->
    <el-dialog title="通过审核" :visible.sync="openPass" width="500px" append-to-body>
      <el-form ref="form" :model="bo" :rules="rules" label-width="80px">
        <el-form-item label="操作备注" prop="reason">
          <el-input v-model="bo.reason" placeholder="请输入操作备注"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="toPass">确 定</el-button>
        <el-button @click="openPass=false">取 消</el-button>
      </div>
    </el-dialog>


    <!--拒绝审核 -->
    <el-dialog title="拒绝审核" :visible.sync="openRefuse" width="500px" append-to-body>
      <el-form ref="form" :model="bo" :rules="rules" label-width="80px">
        <el-form-item label="操作备注" prop="reason">
          <el-input v-model="bo.reason" placeholder="请输入操作备注"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="toRefuse">确 定</el-button>
        <el-button @click="openRefuse=false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {listLikeWall, pass, refuse} from "@/api/service/likewall/likeWall";

export default {
  name: "LikeWall",
  dicts: ['app_likes_wall', 'app_check_status'],
  data() {
    return {
      bo: {},
      openRefuse: false,
      openPass: false,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 贴贴墙表格数据
      likeWallList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: undefined,
        status: '1',
      },
      // 表单参数
      form: {},
      // 表单校验

    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 审核通过 */
    handlePass(row) {
      this.bo.id = row.id
      this.openPass = true;
    },

    /** 删除按钮操作 */
    handleRefuse(row) {
      this.bo.id = row.id
      this.openRefuse = true;
    },
    toPass() {
      pass(this.bo).then(response => {
        this.$modal.msgSuccess("操作成功");
        this.openPass = false;
        this.getList();
      }).finally(() => {
        this.buttonLoading = false;
      });
    },
    toRefuse() {
      refuse(this.bo).then(response => {
        this.$modal.msgSuccess("操作成功");
        this.openRefuse = false;
        this.getList();
      }).finally(() => {
        this.buttonLoading = false;
      });
    },
    /** 查询贴贴墙列表 */
    getList() {
      this.loading = true;
      listLikeWall(this.queryParams).then(response => {
        this.likeWallList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        createTime: undefined,
        createBy: undefined,
        updateTime: undefined,
        updateBy: undefined,
        userId: undefined,
        content: undefined,
        type: undefined,
        nums: undefined,
        status: undefined,
        sex: undefined,
        age: undefined,
        height: undefined,
        headInfo: undefined,
        profession: undefined,
        cityName: undefined,
        pubHeadUrl: undefined,
        platformId: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /**
     * 点击用户爱动id跳转到用户页面
     * @param platformId
     */
    toUserInfo(platformId) {
      this.$router.push({path: "/user/appUser", query: {id: platformId}});
    }

  }
};
</script>
